<template>
  <div>
    <ConTitle :topTitle="topTitle"> </ConTitle>
    <el-form
      label-width="100px"
      :model="ruleForm"
      :rules="rules"
      ref="ruleForm"
    >
      <el-form-item label="标签" prop="security">
        <el-input v-model="ruleForm.security" placeholder="超级用户"></el-input>
      </el-form-item>
      <el-form-item label="访问权限" prop="username">
        <el-input v-model="ruleForm.username" placeholder="8"></el-input>
      </el-form-item>
      <el-form-item label="密钥状态" prop="type">
        <el-select v-model="ruleForm.type" placeholder="未使用">
          <el-option label="使用中" value="true"></el-option>
          <el-option label="未使用" value="false"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="备注" prop="desc">
        <el-input v-model="ruleForm.desc"></el-input>
      </el-form-item>

      <el-form-item>
        <template>
          <el-button type="primary" @click="onSubmit">确认</el-button>
          <el-button>取消</el-button>
        </template>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import { $securityadd } from "@/api";
import ConTitle from "@/components/ConTitle.vue";
export default {
  name: "SecuriTy",
  data() {
    return {
      topTitle: {
        type: "子账号", //非首页，显示上一级
        text: "添加子账号",
        msg: "可添加当前组织的子账号，并为其分配权限",
      },
      ruleForm: {
        security: "",
        username: "",
        type: "",
        desc: "",
      },
      rules: {
        username: [{ required: true, message: "请输入账号", trigger: "blur" }],
        security: [
          { required: true, message: "请选择用户名", trigger: "change" },
        ],
        type: [
          { required: true, message: "请确认密钥状态", trigger: "change" },
        ],
        desc: [{ required: true, message: "请填写备注信息", trigger: "blur" }],
      },
    };
  },
  components: {
    ConTitle,
  },
  methods: {
    onSubmit() {
      $securityadd(this.ruleForm).then((res) => {
        if (res.msg == "success") {
          this.$router.push("/securi/seclist");
        } else {
          return false;
        }
      });
    },
  },
};
</script>

<style lang="scss" scoped>
.el-form {
  background: white;
  margin-top: 10px;
  .el-input {
    width: 222px;
  }
}
</style>